package com.yunfeisoft.business.service.impl;

import com.yunfeisoft.base.model.WorkflowInstance;
import com.yunfeisoft.business.dao.inter.ReceiveApplyDao;
import com.yunfeisoft.business.model.ReceiveApply;
import com.yunfeisoft.business.service.inter.ReceiveApplyService;
import com.yunfeisoft.common.base.BaseServiceImpl;
import com.yunfeisoft.common.utils.DateUtils;
import com.yunfeisoft.common.utils.Page;
import com.yunfeisoft.utils.WorkflowHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * ClassName: ReceiveApplyServiceImpl
 * Description: 接待申请单service实现
 * Author: Jackie liu
 * Date: 2020-01-09
 */
@Service("receiveApplyService")
public class ReceiveApplyServiceImpl extends BaseServiceImpl<ReceiveApply, String, ReceiveApplyDao> implements ReceiveApplyService {

    @Autowired
    private WorkflowHelper workflowHelper;

    @Override
    public Page<ReceiveApply> queryPage(Map<String, Object> params) {
        return getDao().queryPage(params);
    }

    @Override
    public int save(ReceiveApply receiveApply) {
        int result = super.save(receiveApply);

        WorkflowInstance instance = new WorkflowInstance();
        instance.setWorkflowDefineId(receiveApply.getWorkflowDefineId());
        instance.setFormId(receiveApply.getId());
        instance.setTitle("接待申请单:" + DateUtils.getNowTime());

        workflowHelper.saveAndStartProcess(instance, receiveApply.getNextStepUserId());
        return result;
    }
}